<?php
/* 本方法只适用于纯php代码 */
/* gzencode only support php 5.4+ */

$loadFileName = "../original.php";
$saveFileName = "encrypting.php";
//先用gzip加密还是先用base64加密
$encryptingPre = 1; 	//['1'=>base64,'2'=>gzip]
//gzip加密方式
$encryptingType = 1;	//["1"=>'ZLIB', "2"=>'DEFLATE', "3"=>'GZIP']
//DEFLATE、zlib、gzip的压缩效果递减。

//读取文件
$file = file_get_contents( $loadFileName );
$deal = str_replace( "<?php\n", "", $file );
if ( $encryptingPre == 1 ){
	$deal = base64_encode($deal);
}

switch ( $encryptingType ) {
	case 1:
		$deal = gzcompress( $deal );	//ZLIB
		if ( $encryptingPre != 1 ){
			$deal = base64_encode($deal);
			$deal = "gzuncompress(base64_decode(\"{$deal}\"))";
		} else {
			$deal = "base64_decode(gzuncompress(\"{$deal}\"))";
		}
		break;
	case 2:
		$deal = gzdeflate( $deal );	//DEFLATE
		if ( $encryptingPre != 1 ){
			$deal = base64_encode($deal);
			$deal = "gzinflate(base64_decode(\"{$deal}\"))";
		} else {
			$deal = "base64_decode(gzinflate(\"{$deal}\"))";
		}
		break;
	case 3:
	default:
		$deal = gzencode( $deal );	//GZIP
		if ( $encryptingPre != 1 ){
			$deal = base64_encode( $deal );
			$deal = "gzdecode(base64_decode(\"{$deal}\"))";
		} else {
			$deal = "base64_decode(gzdecode(\"{$deal}\"))";
		}
		break;
}
$eval = 
"<?php
eval({$deal});
";
echo $eval;
file_put_contents( $saveFileName , $eval );
exit();

//PHP的压缩函数实现	http://www.jb51.net/article/78791.htm
//php字符串压缩   	https://www.cnblogs.com/lizhaoyao/p/6289824.html